package com.hxzy.boot.old.requestcontroller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wzm
 * @create 2023-09-23 9:12
 * project_name:javaweb2308
 */
@RestController
public class RequestController01 {

    //1.测试控制获取简单参数
  /*  //1.1可以使用原生的Servlet方法获取请求参数
    @RequestMapping("/request01")
    public String req01(HttpServletRequest request){
        //通用的获取参数方式获取
        String name = request.getParameter("name");//name请求的参数名
        String ageStr = request.getParameter("age");

        int age = Integer.parseInt(ageStr);
        System.out.println(name + " " + age);

        return "ok!!!";
    }*/


    /*//1.2SpringBoot方式
    @RequestMapping("/request01")
    public String req01(Integer age,String name){//形参名与请求参数一致
        System.out.println(name + " " + age);
        return "ok!!!";
    }*/


    //将形参名和请求变量设置不一致
  /*  @RequestMapping("/request01")
    public String req01(Integer age,String username){//形参名与请求参数不同
        System.out.println(username + " " + age);//username null
        return "ok!!!";
    }*/

    @RequestMapping("/request01")
    public String req01(Integer age,@RequestParam(name = "name",required = false) String username){//形参名与请求参数不同
        System.out.println(username + " " + age);//username null
        return "ok!!!";
    }


}
